<?php
include_once '../inc/config_inc.php';
include_once '../inc/mysql_inc.php';
include_once '../inc/tool_inc.php';
$link=connect();
if(isset($_POST['submit'])){
	foreach ($_POST['sort'] as $key => $val) {
		if(!is_numeric($val) || !is_numeric($key)){
			skip('life.php','error','排序参数错误!');exit();
		}
		$query[]="update life set sort={$val} where id={$key}";
	}
	if(execute_multi($link,$query,$error)){
		skip('life.php','ok','排序修改成功!'); exit();
	}else{
		skip('life.php','error','$error');exit();
	}
}

$template['title']='慢生活列表页'; 
$template['css']=array('style/public.css');
?>

<?php include 'inc/header_inc.php'; ?>
<div id="main">
		<div class="title">慢生活列表</div>
		<form method="post">
		<table class="list">
			<tr>
				<th>排序</th>	 	 	
				<th>标题</th>
				<th>发表时间</th>
				<th>浏览</th>
				<th>操作</th>	
			</tr>
			<?php
				$query="select * from life";
				$result=execute($link,$query);
				while($data=mysqli_fetch_assoc($result)){
					$url=urlencode("life_delete.php?id={$data['id']}");
					$return_url=urlencode($_SERVER['REQUEST_URI']);
					$message="你真的要删除该慢生活吗?";
					$delete_url="confirm.php?url={$url}&return_url={$return_url}&message={$message}";
$html=<<<A
            <tr>
            	<td><input class="sort" type="text" name="sort[{$data['id']}]" value="{$data['sort']}" /></td>
				<td>{$data['title']}</td>
				<td>{$data['create_time']}</td>
				<td>{$data['times']}</td>
		    	<td><a href="life_update.php?id={$data['id']}">[修改]</a>&nbsp;&nbsp;<a href="$delete_url">[删除]</a></td>
         	</tr>
A;
					echo $html;		    
				}
			?>	    
		</table>
		<input style="margin-top:20px; cursor: pointer;" class="btn" type="submit" name="submit" value="修改排序" />
	</form>
</div>

<?php include 'inc/footer_inc.php'; ?>